package com.controller;

import com.domain.Users;
import com.service.UsersService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/users")
public class UsersController {
    @Resource
    private UsersService usersService;
    @RequestMapping("/addUser.do")
    public ModelAndView addUsers(Users users){
        ModelAndView mv=new ModelAndView();
        String tips="注册失败！";
        int nums=usersService.addUsers(users);
        if (nums>0)
        {
            tips=users.getUsername()+"注册成功！";
        }
        mv.addObject("tips",tips);
        mv.setViewName("result");
        return mv;
    }
    @RequestMapping("/queryUser.do")
    @ResponseBody
    public List<Users> queryString(String username,String addr){
        List<Users> list=null;
        try {
            if(username=="")
                username=null;
            if(addr=="")
                addr=null;
             list=usersService.findUsers(username,addr);
            return list;
        }catch (Exception e){
String ss="1";
        }
        return list;
    }
}
